var approvalType = ly.getUrlParam("approvalType");
var listUrl = ''; // 列表接口
if (approvalType == 1) { // 补卡
  listUrl = site.apiUrl + '/back/approvalSettings/selectCardReissuePacketRecord';
} else if (approvalType == 2) { // 请假
  listUrl = site.apiUrl + '/back/approvalSettings/selectAskForLeavePacketRecordByCondition';
} else if (approvalType == 3) { // 外出
  listUrl = site.apiUrl + '/back/approvalSettings/selectGoOutPacketRecordByCondition';
}

$(function() {
  $('#approvalGroupList').getList({
    "initData": {
      "num": 1,
      "size": 10,
    },
    "url": listUrl, // 数据请求url
    "type": "post",
    // "ajaxform": true,
    "checkname": "datachk", //选择器名称，为空不显示选择器
    "col": [ //数据列
      { "field": "packetName", "display": "分组名称", "width": "1.5" },
    ],
    "option": [ //操作按钮配置 icon: view, edit, add, del
      { "icon": "edit", "tip": "编辑", "fun": "brandEdit('{{id}}')" }, // 花括号内可以对应相关字段
      { "icon": "del", "tip": "删除", "fun": "deleteBrand('{{id}}')" }
    ]
  });

  // 批量删除
  $("#batchDelBtn").click(function() {
    var c = "";
    $("input[name=datachk]:checked").each(function() {
      c += $(this).val() + ',';
    });
    if (c != null && c != '') {
      deleteBrand(c);
    } else {
      ly.toast("请选择删除项");
    }

  });
});

// 编辑
function brandEdit(attendanceId) {
  ly.goto("approval-group-creat.html?id=" + attendanceId + "&attendanceType=2" + "&approvalType=" + approvalType);
}

// 删除
function deleteBrand(attendanceId) {
  var url = site.apiUrl + "/back/approvalSettings/deletePacketRecordByIds";
  ly.confirm("是否删除？", function() {
    request({
      url: url,
      data: {
        "approvalType": approvalType,
        "ids": attendanceId
      },
      type: "post",
      ajaxform: 'true',
      callback: function(f) {
        if (f.code == "rest.success") {
          ly.toast("删除成功");
          $("#approvalGroupList").getList.refresh(); //刷新当前分页
        }
      }
    });
  });
}
